var t = require("../../../mybehaviors/location/location"), a = getApp(), e = Math.PI / 1e3, n = Math.PI / 1e3, i = 0, o = 0, s = 0;

Page({
    behaviors: [ t ],
    data: {
        address: "",
        city: "",
        point: {
            lat: "",
            lng: ""
        },
        bottomList: [],
        navigateList: [],
        timer: "",
        tagEle: [],
        iPnoneBottomBol: !1,
        pluOption: {}
    },
    onLoad: function(t) {
        this.getiPnoneBottom(), this.getAppBottom(), this.getAppNavigate(), this.getAppOption();
    },
    onReady: function() {},
    onShow: function() {
        this.init();
    },
    refreshList: function() {
        this.getAppData(!0);
    },
    getAppData: function(t) {
        var e = this, n = a.getNetAddresss("plugin.tg-decorate.frontend.app.index");
        a._postNetWork({
            url: n,
            data: {
                page_size: 30,
                is_refresh: t || !1,
                longitude: this.data.point.lng,
                latitude: this.data.point.lat,
                city: this.data.city,
                district: this.data.address
            },
            success: function(t) {
                var n = t.data;
                1 == n.result ? n.data.data.forEach(function(t, a) {
                    e.data.tagEle[a].title = t.title, e.data.tagEle[a].color = t.font_color, e.data.tagEle[a].logo = t.logo, 
                    e.data.tagEle[a].link = t.mini;
                }) : (a.tips(n.msg), wx.reLaunch({
                    url: "/packageG/index/index"
                }));
            },
            fail: function(t) {}
        });
    },
    getAppBottom: function() {
        var t = this, e = a.getNetAddresss("plugin.tg-decorate.frontend.app.bottom");
        a._postNetWork({
            url: e,
            data: {},
            success: function(e) {
                var n = e.data;
                1 == n.result ? t.setData({
                    bottomList: n.data
                }) : (a.tips(n.msg), wx.reLaunch({
                    url: "/packageG/index/index"
                }));
            },
            fail: function(t) {}
        });
    },
    getAppNavigate: function() {
        var t = this, e = a.getNetAddresss("plugin.tg-decorate.frontend.navigate.index");
        a._postNetWork({
            url: e,
            data: {},
            success: function(e) {
                var n = e.data;
                1 == n.result ? t.setData({
                    navigateList: n.data
                }) : (a.tips(n.msg), wx.reLaunch({
                    url: "/packageG/index/index"
                }));
            },
            fail: function(t) {}
        });
    },
    getAppOption: function() {
        var t = this, e = a.getNetAddresss("plugin.tg-decorate.frontend.app.set");
        a._postNetWork({
            url: e,
            success: function(a) {
                var e = a.data;
                1 == e.result && (t.setData({
                    pluOption: e.data
                }), wx.setNavigationBarTitle({
                    title: t.data.pluOption.diy_title
                }));
            }
        });
    },
    gotoUrl: function(t) {
        var a = t.currentTarget.dataset.link;
        if ("tag" != t.currentTarget.dataset.type || a || (a = this.data.pluOption.bottom_default_mini), 
        a) try {
            wx.navigateTo({
                url: a
            });
        } catch (t) {
            wx.reLaunch({
                url: a
            });
        }
    },
    tosearch: function() {
        this.data.city ? wx.navigateTo({
            url: "/packageI/tagCloud/search/index?city=" + this.data.city + "&point=" + JSON.stringify(this.data.point)
        }) : wx.showToast({
            icon: "none",
            title: "请先选择城市",
            duration: 1e3
        });
    },
    tolocation: function() {
        wx.navigateTo({
            url: "/packageC/o2o/o2oLocation/o2oLocation?tag=tagCloud"
        });
    },
    init: function() {
        for (var t = this, a = [], e = 0; e < 30; e++) a.push({
            title: "成为合伙人",
            color: "#fff",
            logo: "",
            x: 0,
            y: 0,
            z: 0,
            s: 0,
            o: 1,
            f: 15,
            angleX: 0,
            angleY: 0
        });
        for (var n = 0; n < a.length; n++) {
            var i = (2 * (n + 1) - 1) / a.length - 1, o = Math.acos(i), s = o * Math.sqrt(a.length * Math.PI), c = 140 * Math.sin(o) * Math.cos(s), r = 140 * Math.sin(o) * Math.sin(s), l = 280 * Math.cos(o);
            a[n].x = 2 * c, a[n].y = 2 * r, a[n].z = l, a[n].s = 350 / (640 - a[n].z);
        }
        this.data.timer = setInterval(function() {
            t.setBalls(a);
        }, 16);
        var d = wx.getStorageSync("address-point");
        this.setData({
            address: d.address_component && d.address_component.district || d.city
        }), this.getAppData();
    },
    setBalls: function(t) {
        var a = !0;
        if (1 == a) {
            a = !1;
            for (var i = 0; i < t.length; i++) {
                t[i].s = 350 / (650 - t[i].z);
                var o = Math.cos(n), s = Math.sin(n), c = t[i].y * o - t[i].z * s, r = t[i].z * o + t[i].y * s;
                t[i].y = c, t[i].z = r;
                o = Math.cos(e), s = Math.sin(e);
                var l = t[i].x * o - t[i].z * s;
                r = t[i].z * o + t[i].x * s;
                t[i].x = l, t[i].z = r;
            }
            this.setData({
                tagEle: t
            }), a = !0;
        }
    },
    touchmove: function(t) {
        var a = t.changedTouches[0].clientX - i, s = t.changedTouches[0].clientY - o;
        e = 1e-4 * -a, n = 1e-4 * -s, this.setBalls(this.data.tagEle);
    },
    touchStart: function(t) {
        i = t.changedTouches[0].clientX, o = t.changedTouches[0].clientY, s = new Date().getTime(), 
        clearInterval(this.data.timer);
    },
    touchEnd: function(t) {
        var a = this, c = new Date().getTime() - s;
        i = t.changedTouches[0].clientX - i || 2, o = t.changedTouches[0].clientY - o || 2, 
        0 == c && (c = 100), n = -o / c * .1, e = (e = -i / c * .1) > 0 ? Math.min(e, .01) : Math.max(e, -.01), 
        n = n > 0 ? Math.min(n, .01) : Math.max(n, -.01), this.data.timer = setInterval(function() {
            a.setBalls(a.data.tagEle);
        }, 25);
    },
    getiPnoneBottom: function() {
        try {
            wx.getStorageSync("iPhoneBottom") && this.setData({
                iPnoneBottomBol: !0
            });
        } catch (t) {}
    },
    onHide: function() {
        clearInterval(this.data.timer);
    },
    onUnload: function() {
        clearInterval(this.data.timer);
    },
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {}
});